package yhp.servlet;

import yhp.bean.Users;
import yhp.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

//C-controller 控制层
@WebServlet(urlPatterns = "/getstus")
public class UserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接收jsp的请求参数
        //2.调取service层方法
        UserServiceImpl userService = new UserServiceImpl();
        List<Users> getall = null;
        try {
            getall = userService.getall();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        //3.跳转页面
        //4.后台传递数据前台
        req.setAttribute("userlist",getall);
        req.getRequestDispatcher("/show.jsp").forward(req,resp);
    }
}
